<%-- 
    Document   : index
    Created on : Nov 28, 2011, 12:45:07 PM
    Author     : kamsz
--%>

<%@page import="ForumPackages.Forum"%>
<%@page import="java.util.List"%>
<%@page import="UserPackages.User"%>
<%@page import="javax.persistence.*"%>
<%@page import="CategoryPackages.Category"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Forum</title>
        <link href="style.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
    <div id="login_tekst">
        <%
        if(session.getAttribute("logged")==null) {
            if(request.getParameter("loginResponse")!=null)
                out.println(request.getParameter("loginResponse").toString());
        %>
        <form action="UserLogin" method="post">
            Login:
            <input type="text" name="login"/>
            Hasło:
            <input type="password" name="haslo"/>
            <input id="button_logowanie" type="submit" name="zaloguj" value="Zaloguj" />
            <a href="user_register.jsp">Zarejestruj</a>
        </form>
        <% 
        }
        else {
        %>
            ZALOGOWANY!
        <%
        }
        %>
    </div>
    <div id="menu">
        <div>
            <div>
                <img id="logo_forum" src="obrazki/forumposting1.jpg"/>
                <h1>FORUM</h1>
            </div>
            <div id="naglowek">
                <h2 class="ble">Witamy na forum.pl ;) Dziękujemy za wizytę, czy zostaniesz z nami na dłużej?</h2>
            </div>
        </div>
        <div>
            <%
            EntityManagerFactory emf = Persistence.createEntityManagerFactory("forumPU");
            EntityManager em = emf.createEntityManager();
            Query q = em.createQuery("select x from Category x");
            Query q2 = em.createQuery("select x from Forum x");
            List<Category> categories = q.getResultList();
            List<Forum> forums = q2.getResultList();
            for(Category category : categories) {
            %>
            <div id="kategorie">
            <% out.print(category.getCategory_name()); %>
            </div>
            <div id="dekoracja1"></div>
            <div id="podfora">
            <%
                for(Forum forum : forums) {
                    int compare = forum.getCategory_id().compareTo(Integer.parseInt(category.getId().toString()));
                    if(compare==0) {
                        %><p><%
                        out.print(forum.getForum_name() + " || " + forum.getForum_desc());
                        %></p><%
                    }                  
                }
            %>
            </div>
            <div id="dekoracja2"></div>
            <div id="przerwa"></div>
            <%
            }
            em.close();
            emf.close();
            %>
        </div>
        
    </div>
    <div id="cos">
    </div>
    <div id="footer">
            Justyna Pawłowska & Kamil Szczygieł &copy; 2011
    </div>
        </div>
    </body>
</html>